<?php

namespace app\common\model\system;
use app\common\model\BaseModel;

class Admin extends BaseModel
{

    public static function tablePK(): ?string
    {
        return 'admin_id';
    }

    public static function tableName(): string
    {
        return 'admin';
    }

    public function getRolesAttr($value)
    {
        return array_map('intval', explode(',', $value));
    }


    public function setRolesAttr($value)
    {
        return implode(',', $value);
    }


    public function roleNames($isArray = false)
    {
        $roleNames = SystemRole::getDB()->whereIn('role_id', $this->roles)->column('role_name');
        return $isArray ? $roleNames : implode(',', $roleNames);
    }

    public function searchRealNameAttr($query,$value)
    {
        $query->whereLike('real_name',"%{$value}%");
    }

}